﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 扫描模型管理
/// </summary>
public class XrayModelManager : MonoBehaviour
{
    [Header("所有类型物品")]
    public List<GameObject> All_Items;
    [Header("其他类型物品")]
    public List<GameObject> Weapon_Items;
    public List<GameObject> Tool_Items;
    public List<GameObject> Electronic_Items;
    public List<GameObject> Food_Items;
    public List<GameObject> Bottle_Items;
    [Header("当前携带物品")]
    public List<GameObject> currentItems;
    // 所有的类型
    private List<PassengerType> allTypes = new List<PassengerType>
    {
        PassengerType.Normal,
        PassengerType.Weapons,
        PassengerType.Tools,
        PassengerType.Electronic,
        PassengerType.Foods,
        PassengerType.Bottles
    };

    private void OnEnable()
    {
        currentItems.Clear();
        ShowCarryItems();
    }

    private void OnDisable()
    {
        HideAllItems();
    }

    // 显示携带的物品
    private void ShowCarryItems()
    {
        PassengerType targetType = PassengerManager.Instance.currentPassenger[0].GetComponent<PassengerAnim>().passengerType;

        for (int i = 0; i < Random.Range(1, 3); i++)
        {
            GameObject obj = All_Items[Random.Range(0, All_Items.Count)];
            while (obj.tag == targetType.ToString() || obj.tag == PassengerManager.Instance.scanType.ToString())
                obj = All_Items[Random.Range(0, All_Items.Count)];
            obj.SetActive(true);
            if (!currentItems.Contains(obj))
                currentItems.Add(obj);
        }
        // 目标物品
        if (targetType == PassengerType.Normal)
            return;
        switch (targetType)
        {
            case PassengerType.Weapons:
                for (int i = 0; i < Random.Range(1, 3); i++)
                {
                    GameObject obj = Weapon_Items[Random.Range(0, Weapon_Items.Count)];
                    obj.SetActive(true);
                    if (!currentItems.Contains(obj))
                        currentItems.Add(obj);
                }
                break;
            case PassengerType.Tools:
                for (int i = 0; i < 1; i++)
                {
                    GameObject obj = Tool_Items[Random.Range(0, Tool_Items.Count)];
                    obj.SetActive(true);
                    if (!currentItems.Contains(obj))
                        currentItems.Add(obj);
                }
                break;
            case PassengerType.Electronic:
                for (int i = 0; i < 1; i++)
                {
                    GameObject obj = Electronic_Items[Random.Range(0, Electronic_Items.Count)];
                    obj.SetActive(true);
                    if (!currentItems.Contains(obj))
                        currentItems.Add(obj);
                }
                break;
            case PassengerType.Foods:
                for (int i = 0; i < Random.Range(1, 3); i++)
                {
                    GameObject obj = Food_Items[Random.Range(0, Food_Items.Count)];
                    obj.SetActive(true);
                    if (!currentItems.Contains(obj))
                        currentItems.Add(obj);
                }
                break;
            case PassengerType.Bottles:
                for (int i = 0; i < 1; i++)
                {
                    GameObject obj = Bottle_Items[Random.Range(0, Bottle_Items.Count)];
                    obj.SetActive(true);
                    if (!currentItems.Contains(obj))
                        currentItems.Add(obj);
                }
                break;
        }
    }

    private void HideAllItems()
    {
        for (int i = 0; i < currentItems.Count; i++)
        {
            currentItems[i].SetActive(false);
        }
        currentItems.Clear();
    }
}


